#include<iostream>
#include<stdlib.h>
#include<unistd.h>
#include<signal.h>

using namespace std;

void work()
{
    cout<<"print log..."<<endl;
}

void handler(int signo)
{
    //work();
    cout<<"...get a sig,number:"<<signo<<endl;//我什么都没有干
    int n=alarm(5);
    cout<<"剩余时间:"<<n<<endl;
}

int main()
{
    signal(SIGALRM,handler);
    int n=alarm(5);

    while(1)
    {
        cout<<"proc is running..."<<endl;
        sleep(1);
    }

    /*signal(SIGFPE,handler);
    cout<<"div before"<<endl;

    sleep(5);
    int a=10;
    a/=0;
    cout<<"div after"<<endl;
    sleep(1);*/

    return 0;
}